module MessagesHelper
  
  def rtm_menu
    rtm_link_to_inbox + '|' + rtm_link_to_outbox + '|' + rtm_link_to_compose
  end
  
  def rtm_link_to_inbox
    title = @count_unread == 0 ? 'Inbox' : "Inbox(#{@count_unread})"
    link_to title, inbox_messages_path
  end
  
  def rtm_link_to_outbox
    link_to 'Outbox', outbox_messages_path
  end
  
  def rtm_link_to_compose
    link_to 'Compose', new_message_path
  end
  
  def rtm_sender message
    message.sender.login
  end
  
  def rtm_receivers thread
    receivers = thread.receivers
    receivers.size == 1 ? receivers.first.login : "#{receivers.size} people"
  end
  
  def rtm_send_at message
    message.created_at.to_s :db
  end
  
  def rtm_subject_and_status box_item
    if !box_item.read? && box_item.instance_of?(InboxItem)
      "<b>#{h box_item.message.subject}</b>"
    else
      h box_item.message.subject
    end
  end
  
  def rtm_body message
    simple_format message.body
  end
end
